package cn.com.oidreams.wechat.robot.entity;

import cn.com.oidreams.common.annotations.Required;
import cn.com.oidreams.common.utils.StringUtil;
import cn.com.oidreams.wechat.robot.enums.WeXinTalkEnum;
import lombok.Getter;
import lombok.Setter;

import java.util.Arrays;
import java.util.List;

/***
 ** @category 文本消息
 ** @author qing.yunhui
 ** @email: qingyh@glodon.com
 ** @createTime: 2021-12-14 19:17
 **/
@Getter
@Setter
public class TextMsgRequest extends BaseRequest{

    @Required(errorMsg = "内容必填",classParse = false)
    private Text text;

    public TextMsgRequest(Text text) {
        super.setMsgtype(WeXinTalkEnum.MSG_TYPE.TEXT.getCode());
        this.text = text;
    }

    @Getter
    @Setter
    public static class Text {
        public Text(String content,WeXinTalkEnum.AT_TYPE atType,String ...members) {
            this.content = content;
            if(null!=atType && !StringUtil.isEmptys(members)){
                if(WeXinTalkEnum.AT_TYPE.USER_ID.getCode().equals(atType.getCode())){
                    this.mentioned_list = Arrays.asList(members);
                }else if(WeXinTalkEnum.AT_TYPE.MOBILE.getCode().equals(atType.getCode())){
                    this.mentioned_mobile_list = Arrays.asList(members);
                }
            }
        }
        public Text(String content){ this(content,null,null); }

        @Required(errorMsg = "消息内容不能为空",remark="文本内容，最长不超过2048个字节，必须是utf8编码",classParse = false)
        private String content;
        /**
         * <p>userid的列表，提醒群中的指定成员(@某个成员)，@all表示提醒所有人，如果开发者获取不到userid，可以使用mentioned_mobile_list</p>
         * */
        private List<String> mentioned_list;
        /**
         * <p>手机号列表，提醒手机号对应的群成员(@某个成员)，@all表示提醒所有人</p>
         * */
        private List<String> mentioned_mobile_list;
    }
}
